import {Component, Input, OnInit} from '@angular/core';
import { Router } from '@angular/router';
import { MatDialog } from '@angular/material';
import { NewProjectComponent } from '../new-project/new-project.component';
import { InviteComponent } from '../invite/invite.component';

@Component({
  selector: 'app-project-list',
  templateUrl: './project-list.component.html',
  styleUrls: ['./project-list.component.scss']
})
export class ProjectListComponent implements OnInit {
  // @Input() darkTheme;
  projects: object[];
  constructor(
    private router: Router,
    public dialog: MatDialog
  ) { }

  ngOnInit() {
    this.projects = [
      {
        name: '项目1',
        desc: '这是一个项目描述',
        imgSrc: 'http://via.placeholder.com/250x150'
      },
      {
        name: '项目2',
        desc: '这是一个项目描述',
        imgSrc: 'http://via.placeholder.com/250x150'
      },
      {
        name: '项目3',
        desc: '这是一个项目描述',
        imgSrc: 'http://via.placeholder.com/250x150'
      },
    ];
    console.log(this.projects);
  }
  viewItem(index: number) {
    this.router.navigate(['/project', index + 1]);
  }

  /**
   * 打开新建项目模态
   */
  openNewProjectModal(): void {
    const dialogRef = this.dialog.open(NewProjectComponent, {
      // width: '250',
      // position: { left: '0', top: '0' },
      data: {
        name: 'data data data!!!',
        desc: 'desc desc desc',
        darkTheme: false
      }
    });

    dialogRef.afterClosed().subscribe(result => console.log(result));
  }
  /**
   * 打开邀请成员模态
   */
  openInviteMemberModal(): void {
    const dialogRef = this.dialog.open(InviteComponent, {
      data: {
        width: '400',
        name: 'data data data!!!',
        desc: 'desc desc desc',
        darkTheme: false
      }
    });

    dialogRef.afterClosed().subscribe(result => console.log(result));
  }
}
